<template>
    <div class="detail-header" v-scroll="scrolltop">
        <i class="iconfont icon-zuojiantou leftBtn" @click="handleBack"></i>
        <slot></slot>
    </div>
</template>

<script>
import Vue from 'vue'

Vue.directive('scroll', {
  inserted (el, binding) {
    el.style.opacity = 0
    window.onscroll = () => {
      const scrollTop = document.documentElement.scrollTop || document.body.scrollTop
      if (scrollTop > binding.value) {
        el.style.opacity = 1
      } else {
        el.style.opacity = 0
      }
    }
  },
  // 销毁
  unbind () {
    window.onscroll = null
  }
})

export default {
  props: {
    scrolltop: String
  },
  data () {
    return {

    }
  },
  methods: {
    handleBack () {
      this.$router.back()
    }
  }
}
</script>

<style lang="scss" scoped>
.detail-header {
  width: 100%;
  height: 44px;
  line-height: 44px;
  background-color: #fff;
  text-align: center;
  font-size: 17px;
  position: fixed;
  top: 0;
  transition: all .3s;
}

.leftBtn {
  color: #4D4F50;
  font-size: 26px;
  position: fixed;
  left: 7px;
}
</style>
